package com.example.daxiguaforharmony.game;

import com.example.daxiguaforharmony.ResourceTable;
import ohos.agp.components.Image;
import ohos.agp.render.PixelMapHolder;
import ohos.app.Context;

import java.util.HashMap;
import java.util.Map;

public class AssetManager {
    private static AssetManager _instance = null;
    public static AssetManager getInstance() {
        if (_instance == null) {
            synchronized (AssetManager.class) {
                if (_instance == null) _instance = new AssetManager();
            }
        }
        return _instance;
    }

    private Map<String, PixelMapHolder> _fruitsImages = null;

    public AssetManager() {
        this._fruitsImages = new HashMap<String, PixelMapHolder>();
    }

    public void loadFruits(Context context) {
        Image image = new Image(context);
        image.setPixelMap(ResourceTable.Media_xigua1);
        AssetManager.getInstance().addFruits("f1", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_xigua2);
        AssetManager.getInstance().addFruits("f2", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_xigua3);
        AssetManager.getInstance().addFruits("f3", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_xigua4);
        AssetManager.getInstance().addFruits("f4", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_xigua5);
        AssetManager.getInstance().addFruits("f5", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_xigua6);
        AssetManager.getInstance().addFruits("f6", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_xigua7);
        AssetManager.getInstance().addFruits("f7", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_xigua8);
        AssetManager.getInstance().addFruits("f8", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_xigua9);
        AssetManager.getInstance().addFruits("f9", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_xigua10);
        AssetManager.getInstance().addFruits("f10", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_xigua11);
        AssetManager.getInstance().addFruits("f11", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_num1);
        AssetManager.getInstance().addFruits("num1", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_bgdi);
        AssetManager.getInstance().addFruits("bgdi", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_line_red);
        AssetManager.getInstance().addFruits("overline1", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_kuang);
        AssetManager.getInstance().addFruits("kuang1", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_a1);
        AssetManager.getInstance().addFruits("a1", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_a2);
        AssetManager.getInstance().addFruits("a2", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_a3);
        AssetManager.getInstance().addFruits("a3", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_a4);
        AssetManager.getInstance().addFruits("a4", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_a5);
        AssetManager.getInstance().addFruits("a5", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_a6);
        AssetManager.getInstance().addFruits("a6", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_a7);
        AssetManager.getInstance().addFruits("a7", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_a8);
        AssetManager.getInstance().addFruits("a8", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_a9);
        AssetManager.getInstance().addFruits("a9", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_a10);
        AssetManager.getInstance().addFruits("a10", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_b1);
        AssetManager.getInstance().addFruits("b1", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_b2);
        AssetManager.getInstance().addFruits("b2", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_b3);
        AssetManager.getInstance().addFruits("b3", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_b4);
        AssetManager.getInstance().addFruits("b4", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_b5);
        AssetManager.getInstance().addFruits("b5", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_b6);
        AssetManager.getInstance().addFruits("b6", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_b7);
        AssetManager.getInstance().addFruits("b7", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_b8);
        AssetManager.getInstance().addFruits("b8", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_b9);
        AssetManager.getInstance().addFruits("b9", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_b10);
        AssetManager.getInstance().addFruits("b10", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_c1);
        AssetManager.getInstance().addFruits("c1", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_c2);
        AssetManager.getInstance().addFruits("c2", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_c3);
        AssetManager.getInstance().addFruits("c3", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_c4);
        AssetManager.getInstance().addFruits("c4", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_c5);
        AssetManager.getInstance().addFruits("c5", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_c6);
        AssetManager.getInstance().addFruits("c6", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_c7);
        AssetManager.getInstance().addFruits("c7", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_c8);
        AssetManager.getInstance().addFruits("c8", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_c9);
        AssetManager.getInstance().addFruits("c9", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_c10);
        AssetManager.getInstance().addFruits("c10", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_1001s);
        AssetManager.getInstance().addFruits("item1001", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_1002s);
        AssetManager.getInstance().addFruits("item1002", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_1003s);
        AssetManager.getInstance().addFruits("item1003", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_1004s);
        AssetManager.getInstance().addFruits("item1004", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_bg);
        AssetManager.getInstance().addFruits("loading_bg", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_logo);
        AssetManager.getInstance().addFruits("logo", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_btn_play);
        AssetManager.getInstance().addFruits("btn_play", image.getPixelMapHolder());
        image = new Image(context);
        image.setPixelMap(ResourceTable.Media_help);
        AssetManager.getInstance().addFruits("btn_help", image.getPixelMapHolder());
    }

    public void addFruits(String name, PixelMapHolder pixelMapHolder) {
        this._fruitsImages.put(name, pixelMapHolder);
    }

    public PixelMapHolder getFruits(String name) {
        if (this._fruitsImages.containsKey(name) == true) {
            PixelMapHolder pixelMapHolder = this._fruitsImages.get(name);
            return pixelMapHolder;
        }
        return null;
    }
}
